package cn.com.dcsgo.config;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * Web容器配置
 *
 * @author Dcsgo
 * @since 2025/3/8 15:48
 */
@EnableWebMvc
@Configuration
@ComponentScan({"cn.com.dcsgo.controller"})
public class WebConfig implements WebMvcConfigurer {
    /**
     * 配置静态资源处理
     * 启用默认servlet处理器
     *
     * @param configurer configurer
     */
    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
        configurer.enable();
    }

    /**
     * 配置视图解析器
     * 自动将 xxx 转化为 /WEB-INF/views/xxx.jsp
     *
     * @param registry registry
     */
    @Override
    public void configureViewResolvers(ViewResolverRegistry registry) {
        registry.jsp("/WEB-INF/views/", ".jsp");
    }

    /**
     * 添加拦截器
     *
     * @param registry registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyWebHandlerInterceptor());
    }
}
